package com.huangj.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.huangj.entity.HomeInfoEntity;
import com.huangj.pro2_h2pop.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by HuangJ on 2016/10/5.14:42
 */
public class Lv3PicsAdapter extends BaseAdapter {

    private Context context;
    private List<HomeInfoEntity.DataBean.SectionsBean.ModelsBean> datas;

    public Lv3PicsAdapter(Context context) {
        this.context = context;
        this.datas = new ArrayList<>();
    }
    public  void  setDatas(List<HomeInfoEntity.DataBean.SectionsBean.ModelsBean> datas){
        this.datas = datas;
        this.notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder ;
        if (convertView != null){
            viewHolder = (ViewHolder) convertView.getTag();
        }else{
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.pics_lv3pic,null);
            viewHolder.tv_lv3pictitle = (TextView) convertView.findViewById(R.id.tv_lv3pictitle);
            viewHolder.tv_lv3picbottom = (TextView) convertView.findViewById(R.id.tv_lv3picbottom);
            viewHolder.imageView = (ImageView) convertView.findViewById(R.id.lv3_pic);
            convertView.setTag(viewHolder);
        }
        viewHolder.tv_lv3pictitle.setText(datas.get(position).getTitle());
        viewHolder.tv_lv3picbottom.setText(datas.get(position).getSummary());
        Glide.with(context).load(datas.get(position).getPhoto().getPhoto_url())
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .crossFade()
                .thumbnail(0.1f)
                .into(viewHolder.imageView);
        return convertView;
    }

    class ViewHolder{
        TextView tv_lv3pictitle,tv_lv3picbottom;
        ImageView imageView;
    }
}
